import random

from core.models import Rating, Restaurant, Sale, Staff, StaffRestaurant
from django.contrib.auth.models import User
from django.utils import timezone
from django.db.models import Avg, Value, CharField, Sum, Count, F, Q
from django.db.models.functions import Lower, Concat


def run():
    sales = Sale.objects.filter(expenditure__gt=F('income'))
    print(sales)
    sales = Sale.objects.annotate(profit=F('income') - F('expenditure')).order_by('profit')
    for sale in sales:
        print(sale.profit)

    sales = Sale.objects.aggregate(
        profit=Count('id', filter=Q(income__gt=F('expenditure'))),
        loss=Count('id', filter=Q(income__lt=F('expenditure'))),
    )
    print(sales)

    rating = Rating.objects.first()
    print(rating.rating)

    rating.rating = F('rating') + 1
    print(rating.rating)
    rating.refresh_from_db()
    print(rating.rating)
